/**
* threadtestsimple.cpp aka Thread Racer!
* This program is the test harness we use to test the Platinum::Thread library
*/

#include <iostream>
#include "platinum.h"

Platinum::Thread::Mutex mutex;
void Print( void* data ) {
    char* c = reinterpret_cast<char*>(data);
      Platinum::Thread::Yield();

     for( int i = 0; i < 200; i++ ) {
        mutex.Lock();
        for( int j = 0; j < 5; j++ ) {
            std::cout << c;
            std::cout.flush();
        }
        mutex.Unlock();
        Platinum::Thread::Yield();
    }
}

int main() {
    using namespace Platinum;

	char x; //dummy data to cause program to wait before exiting

    Thread::ThreadID tFirst = Thread::Create( Print,(void*) "1" );
    Thread::ThreadID tSecond = Thread::Create( Print,(void*) "2" );
    Thread::ThreadID tThird = Thread::Create( Print,(void*) "3" );
    Thread::ThreadID tFourth = Thread::Create( Print,(void*) "4" );

    Thread::WaitForFinish( tFourth );
    Thread::WaitForFinish( tThird );
    Thread::WaitForFinish( tSecond );
    Thread::WaitForFinish( tFirst );

	std::cout<<"\nPress the enter key to exit\n";
		std::cin >> x;
    return 0;
}
